﻿using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mes.Application.Services.Quartz
{
    public static class QuartzJobService
    {
        public static void AddQuartzJobService(this IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton<IJobFactory, QuartzJobFactory>();
            services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
            services.AddSingleton<QuartzMiddleJob>();
            services.AddSingleton<MyJobs>();
            services.AddSingleton(new QuartzJobSchedule(typeof(MyJobs), "* * * * * ?", DateTime.Now, DateTime.MaxValue));

            services.AddHostedService<QuartzJobHostService>();
        }
    }
}
